package com.wind.task;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.wind.util.Tools;
//https://blog.csdn.net/u011179993/article/details/74791304
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class InsertTask {
    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;
    
    @Mapper
    public void select() {
//        System.out.println("暂时注销拨打4008电话");//只要在这里注销就行了
    	add();
    }
    
    public int add() {
        String sql = "INSERT INTO donjin.zjz_message (   add_date,  update_date,  state,  is_success,  count,  aj_message,  phone_1,  phone_2,  server_ip,  title_1,  title_2,  title,  yw_id,  is_gd)" +
                "values(now(),now(),0,0,0,'phone_1','4008218851','4008218851','','确认请按1，确认请按1,确认请按1','确认请按1，确认请按1,确认请按1','播放固定录音','01','1')";


//        String sql = "INSERT INTO donjin.zjz_message (   add_date,  update_date,  state,  is_success,  count,  aj_message,  phone_1,  phone_2,  server_ip,  title_1,  title_2,  title,  yw_id,  is_gd)" +
//                "values(now(),now(),0,0,0,'phone_1','17701848563','17701848563','','确认请按1，确认请按1,确认请按1','确认请按1，确认请按1,确认请按1','播放固定录音','01','1')";
        System.out.println(sql);
        Map<String, Object> param = new HashMap<>();
        return (int) jdbcTemplate.update(sql,param);
    }
    //3.添加定时任务
    //"0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟 
    //0 0/30 9-17 * * ?   朝九晚五工作时间内每半小时
    @Scheduled(cron = "0 0/10 6-16 * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
//    @Scheduled(cron = "0 0/50 15-16 * * ?")
    private void configureTasks() {
    	select();
    }

    @Scheduled(cron = "0 0/30 17-23 * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void nightconfigureTasks() {
        select();
    }
/**
MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource()
        .addValue("id", UUID.randomUUID().toString())
        .addValue("name", "小王")
        .addValue("homeAddress", "美国");
template.update("insert into student(id,name,home_address) values    
                   (:id,:name,:homeAddress)",mapSqlParameterSource);

 */
}